# Maintainer: Konstantin Podsvirov <konstantin@podsvirov.pro>

_realname=cargo-local-registry
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.2.6
pkgrel=2
pkgdesc="A cargo subcommand to manage local registries (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64' 'clang32')
url="https://github.com/dhovart/cargo-local-registry"
license=('MIT' 'Apache')
makedepends=("${MINGW_PACKAGE_PREFIX}-rust")
options=('staticlibs' 'strip')
source=("$_realname-$pkgver.tar.gz::$url/archive/$pkgver.tar.gz")
sha256sums=('b42e4904e4db100c27d81cf94a034438b20ae6dbb34d0fee39012f2d548680ca')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"

  # update windows-targets to fix windows-gnullvm dependency specification
  "${MINGW_PREFIX}/bin/cargo.exe" update -p windows-targets@0.48.0 --precise 0.48.1
  "${MINGW_PREFIX}/bin/cargo.exe" fetch --locked
}

build() {
  msg "Cargo build for ${MSYSTEM}"
  cd "${srcdir}"
  cp -r "${_realname}-${pkgver}" "build-${MSYSTEM}"
  cd "build-${MSYSTEM}"

  "${MINGW_PREFIX}/bin/cargo.exe" build \
    --release \
    --locked
}

check() {
  cd "${srcdir}/build-${MSYSTEM}"

  "${MINGW_PREFIX}/bin/cargo.exe" test \
    --release \
    --locked
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"

  install -Dm755 "target/release/${_realname}.exe" "${pkgdir}${MINGW_PREFIX}/bin/${_realname}.exe"
  install -Dm644 "README.md" "${pkgdir}${MINGW_PREFIX}/share/doc/${_realname}/README.md"
  install -Dm644 "LICENSE-MIT" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE-MIT"
  install -Dm644 "LICENSE-APACHE" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE-APACHE"
}

